#ifndef _PARTHUS_TEST_SUPPORT_
#define _PARTHUS_TEST_SUPPORT_
/******************************************************************************
 * MODULE NAME:    test_support.h
 * PROJECT CODE:    BlueStream
 * DESCRIPTION:    Support functionality for Tests
 * MAINTAINER:     John Nelson
 * DATE:           27 Nov 1999
 *
 * SOURCE CONTROL: $Id: test_support.h,v 1.1 2008/02/03 09:39:38 james Exp $
 *
 * LICENSE:
 *     This source code is copyright (c) 1999-2004 Ceva Inc.
 *     All rights reserved.
 *
 * REVISION HISTORY:
 *    27 Nove 1999 -   jn       - Initial Version V1.0
 *
 ******************************************************************************/
#include "sys_config.h"
#include "lc_types.h"
#include "lslc_stat.h"

/* 
 * Logging levels for pDebugPrint 
 */
#define pLOGASIS		1
#define pLOGFATAL		2
#define pLOGCRITICAL	4
#define pLOGERROR		6
#define pLOGWARNING		8
#define pLOGNOTICE		10
#define pLOGDEBUG		12

/*
 * Logging levels which will log only if logging is turned on e.g. -v 2
 */
#define pLOG_IFLOG      0x80
#define pLOGNOTICE_IFLOG  (pLOGNOTICE + pLOG_IFLOG)
#define pLOGDEBUG_IFLOG   (pLOGDEBUG  + pLOG_IFLOG)
#define pLOGASIS_IFLOG    (pLOGASIS   + pLOG_IFLOG)

#define pDEBUGLEVEL     0

#define PRH_SIWAVE1502_RAW_RSSI_DEFAULT_TEST_VALUE 1600


/*
 * Note: SiWave data sheet recommends at least 5 samples used for RSSI average,
 * so a value below 5 must NOT be used for PRH_BS_DL_RSSI_HISTORY_SIZE.
 */
#define PRH_BS_DL_RSSI_HISTORY_SIZE 8 


int Testsup_DebugPrint(int logLevel, char *formatString, ... );
void Testsup_Print_Dashed_Line(int length, char ch);
void Testsup_Print_Dashed_Line_If_Logging(int length, char ch);


#define pDebugPrint  Testsup_DebugPrint

typedef enum {CRC_ERROR=1, CRC_OK=0} t_crc;
typedef enum {HEC_ERROR=1, HEC_OK=0} t_hec;
typedef enum {SEQN_0, SEQN_1, SEQN_ANY, SEQN_EXPECTED} t_seqn;
typedef enum {P_FLOW_0, P_FLOW_1} t_p_flow;
typedef enum {FIRST_HALF_SLOT, SECOND_HALF_SLOT} t_half_slot;

#define AM_ADDR_EXPECTED 0xFF

/*
 * Parameter positions for verification checks.
 */
typedef enum {  RX_PARAM_OK          = 0,
                RX_PARAM_PACKET_TYPE = 0x0001,
                RX_PARAM_AM_ADDR     = 0x0002,
                RX_PARAM_SEQN        = 0x0004,
                RX_PARAM_ARQN        = 0x0008,
                RX_PARAM_FLOW        = 0x0010,
                RX_PARAM_LENGTH      = 0x0020,
                RX_PARAM_PAYLOAD     = 0x0040,
                RX_PARAM_L_CH        = 0x0080,
                RX_PARAM_P_FLOW      = 0x0100,
                RX_PARAM_CRC         = 0x0200,
                RX_PARAM_HEC         = 0x0400,
                RX_PARAM_FREQ        = 0x0800} t_rx_params;

void TESTsup_Initialise_Local_Device(const t_bd_addr *p_bd_addr);
void Testsup_Increment_Clocks(t_clock delta);
void Testsup_Decrement_Clocks(t_clock delta);
t_clock TESTsup_Get_Piconet_Clock(t_deviceIndex device_index);

t_packet Testsup_Process_Rx_Slot(void);
t_packet Testsup_Process_Tx_Slot(void);
void Testsup_Move_to_Rx_in_2nd_half_of_slot(void);
void Testsup_Move_to_Tx_in_2nd_half_of_slot(void);

/*
 * Place the presented packet in the Baseband registers if receiver enabled.
 */
t_packet Testsup_Receive_Packet(t_packet packet_type,
          t_am_addr am_addr, t_seqn seqn, t_arqn arqn, t_flow flow,
          t_length length, const u_int8 * payload, t_LCHmessage l_ch, t_p_flow p_flow,
          t_crc crc, t_hec hec);

u_int32 Testsup_Validate_Receive_Freq(t_freq freq);

u_int32 Testsup_Validate_Rx_Packet_Freq( t_packet packet_type,
t_am_addr am_addr, t_seqn seqn, t_arqn arqn, t_flow flow,
          t_length length, const u_int8 * payload, t_LCHmessage l_ch, t_p_flow p_flow,
          t_crc crc, t_hec hec,
          t_freq freq);

void Testsup_Print_Buffer(const char *descr, const u_int8 *buffer, u_int32 len);

/*
 * Verify that the current packet log matches the expected log
 */
t_error Testsup_Verify_Packet_Log(const t_LLCpacket *Expected_Log, u_int32 size);

/*
 * Verify that previous Tx packet had correct header (packet type + LC flags)
 */
boolean Testsup_Verify_Tx_Packet(t_packet pkt, t_arqn arqn,
                                t_flow flow, t_seqn seqn);
/*
 * Verify that previous Rx packet had correct header (packet type + LC flags)
 */
boolean Testsup_Verify_Rx_Packet(t_packet pkt, t_arqn arqn,
                                t_flow flow, t_seqn seqn);

/*
 *    Check if the Tx message has the presented LMP message opcode
 */
boolean Testsup_Verify_Tx_LMP_Message(u_int32 lmp_message, u_int32 trans_id);


/*
 * LC Comamnds
 */
t_deviceIndex Testsup_Immediate_LC_Connection_to_Slave(
    const t_bd_addr *p_slave_bd_addr, t_clock clke_offset);
t_error Testsup_Setup_LC_Connection_to_Slave(
    const t_bd_addr *p_slave_bd_addr, t_half_slot rx_id_pos, t_clock clke_offset);
t_error Testsup_Setup_LC_Connection_to_Master(
    const t_bd_addr *p_master_bd_addr, t_half_slot rx_id_pos, t_clock fhs_clock);
t_error Testsup_Setup_LC_Connection_to_Master_Ex(
    const t_bd_addr *p_master_bd_addr, t_half_slot rx_id_pos, t_clock fhs_clock,
    boolean fake_ericsson_DM1_resp);

t_error Testsup_Release_LC_Connection(t_deviceIndex device_index);

t_error Testsup_Setup_LC_Inquiry(t_lap inquiry_lap, t_half_slot rx_fhs_pos);
t_error Testsup_Setup_LC_Inquiry_Scan(t_lap inquiry_lap, t_half_slot rx_fhs_pos);

/*
 * HCI Commands for Setting up connections.
 */
void Testsup_Enqueue_HCI_Command(u_int8* command_buf, u_int32 command_len);

t_error Testsup_Setup_HCI_Connection_to_Slave(
        const t_bd_addr *p_slave_bd_addr, t_packetTypes packet_types,
        t_pageScanRepit PSR_Mode, t_pageScanMode PS_Mode,
        t_clock clke_offset, boolean allow_role_switch);

t_error Testsup_Setup_HCI_Connection_to_Slave_Baseband_Only(
        const t_bd_addr *p_slave_bd_addr, t_packetTypes packet_types,
        t_pageScanRepit PSR_Mode, t_pageScanMode PS_Mode,
        t_clock clke_offset, boolean allow_role_switch);

t_error Testsup_Setup_HCI_Connection_to_Master(
        const t_bd_addr *p_master_bd_addr, t_clock fhs_master_clock);

t_error Testsup_Setup_HCI_Connection_to_Master_Baseband_Only(
        const t_bd_addr *p_master_bd_addr, t_clock fhs_master_clock);

t_error Testsup_Setup_HCI_Connection_to_Master_Baseband_Only_Override_Auto_Accept(
        const t_bd_addr *p_master_bd_addr, t_clock fhs_master_clock,
        u_int8 override_auto_accept);

t_error Testsup_Setup_HCI_Connection_to_Master_Baseband_Only_Set_Device_Class(
        const t_bd_addr *p_master_bd_addr, t_clock fhs_master_clock, u_int8 override_auto_accept_flag,
		t_classDevice class_of_device);

t_error Testsup_Release_HCI_Connection(
        const t_bd_addr *p_slave_bd_addr, t_error reason);



t_packet Testsup_Wait_for_Master_Tx(u_int32 valid_packets, u_int32 max_frames);
t_packet Testsup_Wait_for_Master_Default_Tx(void);
void Testsup_Tx_Poll_Rx_Null(u_int16 num_of_frames);
void Testsup_Rx_Poll_Tx_Null(u_int16 num_of_frames);
void Testsup_Rx_Null(void);
void Testsup_Rx_Poll(void);

void TESTsup_Move_HW_Registers_Tx_to_Rx(void);

char const *TESTsup_Get_BT_State_Name(t_state state);
char const *TESTsup_Get_BT_State_Name_Full(t_state state);

char const *TESTsup_Get_TxRxStatus_Name(t_TXRXstatus status);
char const *TESTsup_Get_Packet_Name(t_packet packet);

char const *TESTsup_Get_Testmode_Scenario(u_int8 scenario);
char const *TESTsup_Get_Hopping_Mode(t_rfSelection mode);
char const *TESTsup_Get_Power_Control(u_int8 mode);

char const *TESTsup_Get_BS_PRH_Feature_Name(u_int16 feature_byte_bit);
void TESTsup_Display_LMP_Features(void);
void TESTsup_Display_PRH_Features(void);
void TESTsup_Display_HCI_Commands(void);
void TESTsup_Display_RAM_Usage(void);

t_deviceIndex TESTsup_Get_Device_Index(void);
void TESTsup_Set_Device_Index(t_deviceIndex dev_index);
void TESTsup_Set_ID_FHS_Rx_Position(t_half_slot rx_id_fhs_pos);
t_am_addr TESTsup_Get_AM_Addr(void);
void TESTsup_Set_AM_Addr(t_am_addr am_addr);

void TESTsup_Set_Unit_Test_Select(u_int32 unit_test_select);
u_int32 TESTsup_Get_Unit_Test_Select(void);

void TESTsup_Set_Assert_Off(void);
void TESTsup_Set_Asserts_On(void);
void TESTsup_Set_Error_Messages_Off(void);
void TESTsup_Set_Error_Messages_On(void);
void TESTsup_Set_Logging_On(void);
void TESTsup_Set_Logging_Off(void);
u_int8 TESTsup_Is_Logging_On(void);
u_int8 TESTsup_Is_Logging_Off(void);

void TESTsup_Set_Scheduler_Iterations(u_int32 iterations);
u_int32 TESTsup_Get_Scheduler_Iterations(void);

/*
 * Allow command line argument to specify log level 
 */
typedef enum {
    LOG_IF_LOGGING_ON=0,
    LOG_ALWAYS_OFF=1,
    LOG_ALWAYS_ON=2,
    LOG_EACH_TX_RX_SUMMARY=16,
    LOG_EACH_BASEBAND_TX_RX_DETAILED=32
} t_TESTsup_log_level;

void TESTsup_Set_Log_Level(u_int8 mode);
t_TESTsup_log_level TESTsup_Get_Log_Level(void);


boolean TESTsup_Get_POLL_NULL_in_Three_Slot_eSCO_Instant(void);
void TESTsup_Set_POLL_NULL_in_Three_Slot_eSCO_Instant(boolean setting);

/*
 * Useful macros for test
 */
#define NUM_ELEMENTS(array) ( sizeof(array)/sizeof(array[0]) )

#endif


